//
// Description: 125. 耍杂技的牛
// Created by Loading on 2022/6/5.
//

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> PII;

int main() {
    vector<PII> cows;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int w, s;
        cin >> w >> s;
        // 由于需要按照 w + s 排序，所以 first 直接存储 w + s
        cows.emplace_back(w + s, s);
    }

    // 按照 w + s 排序，结果一定最优
    sort(cows.begin(), cows.end());

    int res = INT_MIN;
    // 累计重量和
    int sum = 0;
    for (auto &cow : cows) {
        int s = cow.second, w = cow.first - s;
        res = max(res, sum - s);
        sum += w;
    }

    cout << res << endl;

    return 0;
}